//
//  XZGroupIntroduceVC.m
//  Teecloud
//
//  Created by PC on 2018/11/15.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZGroupIntroduceVC.h"
#import "XZApplyToJoinGroupVC.h"
#import "XZGroupIntroduce.h"
@interface XZGroupIntroduceVC ()
 @property (nonatomic, strong) UITextView *textView;
@end

@implementation XZGroupIntroduceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.titileStr;
    self.view.backgroundColor = kWhiteColor;
    [self GetGroupInfo];
    [self addLeftBarButtonWithImage:[UIImage imageNamed:@"left-white-64"] action:@selector(left_BarButtonItemAction)];

}
- (void)left_BarButtonItemAction {
    if (kIsEmptyString(self.typeStr)) {
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

- (void)GetGroupInfo{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:FROM_IOS forKey:@"from"];
    [dict setValue:[XGMArchiverTools cacheForKey:BUSIORGID] forKey:@"busiOrgId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_UserId] forKey:@"userId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_identifierNumber] forKey:@"loginFinger"];
    [dict setValue:self.groupId forKey:@"id"];
    
    __weak typeof(self)weakSelf = self;
    [HJNetwork POSTWithURL:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=GetGroupInfo&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                XZGroupIntroduce *model = [XZGroupIntroduce mj_objectWithKeyValues:[responseObject objectForKey:RESULT_NAME_Data]];
                [weakSelf setTextviewText:model.Memo];
                //IsOpenApply为true显示申请加入
                if (model.IsOpenApply) {
                    [self addRightBarButtonItemWithTitle:@"申请加入" action:@selector(applyToJoin)];
                }
            }else{
               
                [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:weakSelf.view];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"请求出错" toView:weakSelf.view];
        }
    }];
}
- (void)setTextviewText:(NSString *)meno{
    NSMutableAttributedString *str=  [[NSMutableAttributedString alloc] initWithData:[meno dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
//    [str addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14] range:NSMakeRange(0, str.length)];
    self.textView.attributedText = str;
}

/**
 申请加入
 */
- (void)applyToJoin{
    XZApplyToJoinGroupVC *appleVC = [[XZApplyToJoinGroupVC alloc]init];
    appleVC.groupId  = self.groupId;
    [self.navigationController pushViewController:appleVC animated:true];
}
- (UITextView *)textView{
    if (!_textView) {
        _textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kBottomSafeHeight)];
        [self.view addSubview:_textView];
    }
    return _textView;
}
@end
